﻿<%@ Page Title="" Language="C#" MasterPageFile="main.Master" AutoEventWireup="true" CodeBehind="books.aspx.cs" Inherits="comix.admininstration.books" %>


<%@ Register Assembly="BasicFrame.WebControls.BasicDatePicker" Namespace="BasicFrame.WebControls" TagPrefix="BDP" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

<script type="text/javascript" src="../swfupload/swfupload.js"></script>
	<script type="text/javascript" src="../js/handlers.js"></script>
	<script type="text/javascript">
	    var swfu;
	    var swfusample;
	    window.onload = function() {
	        try {
	            swfu = new SWFUpload({
	                // Backend Settings
	                upload_url: "../uploadbook.aspx",
	                post_params: {
	                    "ASPSESSID": "<%=Session.SessionID %>",
	                    "BID":"<%=selid %>"
	                },

	                // File Upload Settings
	                file_size_limit: "100 MB",
	                file_types: "*.cmk",
	                file_types_description: "CMK Comix",
	                file_upload_limit: "0",    // Zero means unlimited

	                // Event Handler Settings - these functions as defined in Handlers.js
	                //  The handlers are not part of SWFUpload but are part of my website and control how
	                //  my website reacts to the SWFUpload events.
	                file_queue_error_handler: fileQueueError,
	                file_dialog_complete_handler: fileDialogComplete,
	                upload_progress_handler: uploadProgress,
	                upload_error_handler: uploadError,
	                upload_success_handler: uploadSuccess,
	                upload_complete_handler: uploadComplete,

	                // Button settings
	                button_image_url: "../images/XPButtonNoText_160x22.png",
	                button_placeholder_id: "spanButtonPlaceholder",
	                button_width: 160,
	                button_height: 22,
	                button_text: '<span class="button">Ανέβασμα Αρχείου</span>',
	                button_text_style: '.button { font-family: Helvetica, Arial, sans-serif; font-size: 14pt; } .buttonSmall { font-size: 10pt; }',
	                button_text_top_padding: 1,
	                button_text_left_padding: 5,

	                // Flash Settings
	                flash_url: "../swfupload/swfupload.swf", // Relative to this file

	                custom_settings: {
	                upload_target: "divFileProgressContainer",
	                    upload_name:"fpc"
	                },

	                // Debug Settings
	                debug: false
	            });


	            swfusample = new SWFUpload({
	                // Backend Settings
	            upload_url: "../uploadsample.aspx",
	                post_params: {
	                    "ASPSESSID": "<%=Session.SessionID %>",
	                    "BID":"<%=selid %>"
	                },

	                // File Upload Settings
	                file_size_limit: "100 MB",
	                file_types: "*.cmk",
	                file_types_description: "CMK Comix",
	                file_upload_limit: "0",    // Zero means unlimited

	                // Event Handler Settings - these functions as defined in Handlers.js
	                //  The handlers are not part of SWFUpload but are part of my website and control how
	                //  my website reacts to the SWFUpload events.
	                file_queue_error_handler: fileQueueError,
	                file_dialog_complete_handler: fileDialogComplete,
	                upload_progress_handler: uploadProgress,
	                upload_error_handler: uploadError,
	                upload_success_handler: uploadSuccess,
	                upload_complete_handler: uploadComplete,

	                // Button settings
	                button_image_url: "../images/XPButtonNoText_160x22.png",
	                button_placeholder_id: "spanButtonPlaceholder_sample",
	                button_width: 160,
	                button_height: 22,
	                button_text: '<span class="button">Ανέβασμα Δείγματος</span>',
	                button_text_style: '.button { font-family: Helvetica, Arial, sans-serif; font-size: 14pt; } .buttonSmall { font-size: 10pt; }',
	                button_text_top_padding: 1,
	                button_text_left_padding: 5,

	                // Flash Settings
	                flash_url: "../swfupload/swfupload.swf", // Relative to this file

	                custom_settings: {
	                    upload_target: "divFileProgressContainer_sample",
	                    upload_name: "fpc_sample"
	                },

	                // Debug Settings
	                debug: false
	            });
	        }
	        catch (ex) {
	        }
	    }
	</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <h2>Βιβλία</h2><br />
    <h3>Σειρά:&nbsp;<asp:DropDownList ID="DropDownList1" runat="server" 
            AutoPostBack="True" DataSourceID="SqlDataSource2" DataTextField="ser_name" 
            DataValueField="ser_id">
        </asp:DropDownList>
    </h3>
    
    <asp:ListView ID="ListView1" runat="server" DataKeyNames="bok_id" 
        DataSourceID="SqlDataSource1" InsertItemPosition="LastItem" 
        oniteminserting="ListView1_ItemInserting" 
        onitemupdating="ListView1_ItemUpdating" 
        onitemdatabound="ListView1_ItemDataBound" >
        <ItemTemplate>
            <tr style="">
                <td>
                    <asp:Label ID="Label2" runat="server" Text='<%# Eval("bok_id") %>'  />
                </td>
                <td>
                    <asp:Label ID="pub_nameLabel" runat="server" Text='<%# Eval("bok_title") %>' />
                </td>
                <td>
                    <asp:LinkButton ID="DeleteButton" runat="server" CommandName="Delete" 
                        Text="Διαγραφή" />
                    <asp:LinkButton ID="EditButton" runat="server" CommandName="Edit" Text="Επεξεργασία" />
                </td>                
            </tr>
        </ItemTemplate>
        <AlternatingItemTemplate>
            <tr style="">
                           <td>
                    <asp:Label ID="Label3" runat="server" Text='<%# Eval("bok_id") %>' />
                </td>
                <td>
                    <asp:Label ID="pub_nameLabel" runat="server" Text='<%# Eval("bok_title") %>' />
                </td>
                <td>
                    <asp:LinkButton ID="DeleteButton" runat="server" CommandName="Delete" 
                        Text="Διαγραφή" />
                    <asp:LinkButton ID="EditButton" runat="server" CommandName="Edit" Text="Επεξεργασία" />
                </td>                
            </tr>
        </AlternatingItemTemplate>
        <EmptyDataTemplate>
            <table id="Table1" runat="server" style="">
                <tr>
                    <td>
                        No data was returned.</td>
                </tr>
            </table>
        </EmptyDataTemplate>
        <InsertItemTemplate>
        <tr><td style="height:1px; background-color:Black;" colspan="3" ></td></tr>
        <tr><td colspan="3"><b>Νέο Έντυπο</b></td></tr>
            <tr><td colspan="3"><asp:TextBox ID="TextBox4" Width="80%" runat="server" Text='<%# Bind("bok_title") %>' /></td></tr>
           <tr>
           <td colspan="3">
           <table width="100%">
           <tr>
           <td>Σελίδες:&nbsp; <asp:TextBox ID="TextBox1" Width="30" runat="server" Text='<%# Bind("bok_pages") %>' /></td>
           <td> Αριθμός Σειράς:&nbsp; <asp:TextBox ID="TextBox2" Width="30" runat="server" Text='<%# Bind("bok_ser_index") %>' /></td>
           <td> Ημ/νία έκδοσης:&nbsp;<BDP:BDPLite  DateFormat="ShortDate" Width="50" ID="nws_dateBDP" SelectedDate= '<%# Bind("bok_originalrelease") %>' runat="server"  /></td>
           </tr>
           </table></td>
            </tr>
            <tr><td colspan="3">Περιγραφή</td></tr>
            <tr><td colspan="3"><asp:TextBox ID="TextBox3" runat="server" TextMode="MultiLine" Height="60" Width="100%" Text='<%# Bind("bok_description") %>' /></td></tr>            
            <tr><td colspan="3">
                    <asp:LinkButton ID="InsertButton" runat="server" CommandName="Insert" 
                        Text="Εισαγωγή" />
                </td> </tr>
        </InsertItemTemplate>
        <LayoutTemplate>
            <table id="Table2" runat="server" width="100%">
                <tr id="Tr1" runat="server">
                    <td id="Td1" runat="server">
                        <table ID="itemPlaceholderContainer" runat="server" border="0" style="width:100%">
                            <tr id="Tr2" runat="server" style="">
                                <th id="Th3" runat="server" style="width:10%">
                                    ID</th>
                                <th id="Th1" runat="server" style="width:65%">
                                    Όνομα</th>
                                <th id="Th2" runat="server" style="width:25%">
                                </th>                                                                        
                            </tr>
                            <tr><td style="height:1px; background-color:Black;" colspan="3" ></td></tr>
                            <tr ID="itemPlaceholder" runat="server">
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr><td style="height:1px; background-color:Black;" ></td></tr>
                <tr id="Tr3" runat="server">
                    <td id="Td2" runat="server" style="">
                        <asp:DataPager ID="DataPager1" runat="server">
                            <Fields>
                                <asp:NextPreviousPagerField ButtonType="Link" ShowFirstPageButton="True" FirstPageText="<<"
                                    ShowNextPageButton="False" ShowPreviousPageButton="False" />
                                <asp:NumericPagerField />
                                <asp:NextPreviousPagerField ButtonType="Link" ShowLastPageButton="True" LastPageText=">>"
                                    ShowNextPageButton="False" ShowPreviousPageButton="False" />
                            </Fields>
                        </asp:DataPager>
                    </td>
                </tr>
            </table>
        </LayoutTemplate>
        <EditItemTemplate>
            
            <tr><td colspan="3">
            <table style="background-color:#cccccc; width:100%">
            <tr>
                <td style="width:10%"><asp:Label ID="Label1" Visible="true" runat="server" Text='<%# Eval("bok_id") %>' /></td>
                <td style="width:65%"><asp:TextBox ID="pub_nameTextBox" Width="80%" runat="server" Text='<%# Bind("bok_title") %>' /></td>                
                <td><asp:LinkButton ID="UpdateButton" runat="server" CommandName="Update" 
                        Text="Αποθήκευση" />
                    <asp:LinkButton ID="CancelButton" runat="server" CommandName="Cancel" 
                        Text="Άκυρο" /></td>
            </tr>
           <tr><td colspan="3">Σελίδες:&nbsp; <asp:TextBox ID="TextBox1" Width="30" runat="server" Text='<%# Bind("bok_pages") %>' />&nbsp;&nbsp;
            Αριθμός Σειράς:&nbsp; <asp:TextBox ID="TextBox2" Width="30" runat="server" Text='<%# Bind("bok_ser_index") %>' />&nbsp;&nbsp;
            Ημ/νία έκδοσης:&nbsp;<BDP:BDPLite  DateFormat="ShortDate" Width="50" ID="nws_dateBDP" SelectedDate= '<%# Bind("bok_originalrelease") %>' runat="server"  />&nbsp;&nbsp;
            Τιμή:&nbsp;<asp:DropDownList ID="tiers_list" runat="server" DataSourceID="Tiers" DataTextField="ptr_total" DataValueField="ptr_id" >
               </asp:DropDownList>
               
           </td>
            </tr>
            <tr><td colspan="3">Περιγραφή</td></tr>
            <tr><td colspan="3"><asp:TextBox ID="TextBox3" runat="server" TextMode="MultiLine" Height="60" Width="100%" Text='<%# Bind("bok_description") %>' /></td></tr>
            <tr style="vertical-align:bottom"><td >Εξώφυλλο μικρό:&nbsp;<asp:Image ID="Image1" runat="server" ImageUrl='<%# "../thumbs/small/"+Eval("bok_id").ToString()+".jpg" %>' /></td>
            <td>Εξώφυλλο μεγάλο:&nbsp;<asp:Image ID="Image2" runat="server" ImageUrl='<%# "../thumbs/large/"+Eval("bok_id").ToString()+".jpg" %>' /></td></tr>
            <tr style="height:10px"><td></td></tr>
            <tr style="vertical-align:top"><td><div id="swfu_container" style="margin: 0px 10px;">
		    <div>
				<span id="spanButtonPlaceholder"></span>
		    </div>
		    <div id="divFileProgressContainer" style="height: 75px;"></div>
		    
	    </div></td>
	    <td ><div id="swfu_container_sample" style="margin: 0px 10px;">
		    <div>
				<span id="spanButtonPlaceholder_sample"></span>
		    </div>
		    <div id="divFileProgressContainer_sample" style="height: 75px;"></div>
		    
	    </div>
	    </td><td>
	    <asp:Button ID="Button5" runat="server" Text="Διαγραφή Δείγματος" OnCommand="RemoveSample" CommandArgument='<%# Eval("bok_id").ToString() %>'/></td></tr>
	    
            <tr><td colspan="2">Προεπισκόπηση</td></tr>
            <tr><td colspan="2">Σελίδες Προεπισκόπησης:&nbsp;<asp:TextBox ID="tbpages" runat="server" />&nbsp;<asp:Button ID="Button6" runat="server" Text="Δημιουργία" OnCommand="CreatePreview" CommandArgument='<%# Eval("bok_id").ToString() %>'/>&nbsp;<asp:Button ID="Button7" runat="server" Text="Διαγραφή" OnCommand="DeletePreview" CommandArgument='<%# Eval("bok_id").ToString() %>'/></td></tr>
            <tr><td style="height:10px"></td></tr>
            <tr><td><b>Δημιουργοί:</b></td><td><b>Δημιουργοί τεύχους</b></td></tr>
            <tr><td>
                <asp:ListBox ID="ListBox1" runat="server" SelectionMode="Multiple" DataSourceID="SqlDataSource3" DataTextField="aut_fullname" DataValueField="aut_id"></asp:ListBox>
                &nbsp;<asp:LinkButton ID="LinkButton1" runat="server" OnCommand="onInsertAuthor">Εισαγωγή</asp:LinkButton>
            </td>
            <td colspan="2">
                <asp:GridView Width="100%" ID="GridView1" runat="server" DataSourceID="SqlDataSource4" BorderStyle="None" BorderWidth="0" DataKeyNames="a2b_bok_id,a2b_aut_id" AutoGenerateColumns="false"  >
                    <Columns>
                        <asp:BoundField DataField="aut_fullname" HeaderText="Όνομα" />
                        <asp:CheckBoxField DataField="a2b_is_writter" HeaderText="Συγγραφέας" />
                        <asp:CheckBoxField DataField="a2b_is_designer" HeaderText="Εικονογράφος" />
                        <asp:CommandField ButtonType="Link" ShowEditButton="true" EditText="Επεξεργασία" />
                        <asp:CommandField ButtonType="Link" ShowDeleteButton="true" EditText="Διαγραφή" />
                        
                    </Columns>
                </asp:GridView>
            </td>
            </tr>
<tr><td> </td></tr>
	    
	    
                
                
            <tr><td colspan="2"></td></tr>
                        
            </table>
            </td></tr>                        
<asp:SqlDataSource ID="Tiers" runat="server" 
        ConnectionString="<%$ ConnectionStrings:mainconectionstring %>" 
        SelectCommand="SELECT [ptr_id], [ptr_total] FROM [TIERS] ORDER BY [ptr_id]"></asp:SqlDataSource>
            <asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:mainconectionstring %>" 
        SelectCommand="SELECT aut_id, ISNULL(aut_firstname,'') + ' ' + ISNULL(aut_midname,'') + ' ' + aut_lastname AS aut_fullname FROM AUTHORS INNER JOIN AUTHORS2SERIES ON aut_id = a2s_aut_id WHERE a2s_ser_id = @a2s_ser_id AND a2s_deleted = 0 ORDER BY aut_lastname, aut_firstname">
        <SelectParameters><asp:ControlParameter ControlID="DropDownList1" Name="a2s_ser_id" PropertyName="Text" /></SelectParameters></asp:SqlDataSource>
        <asp:SqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="<%$ ConnectionStrings:mainconectionstring %>" 
        SelectCommand="SELECT aut_id, ISNULL(aut_firstname,'') + ' ' + ISNULL(aut_midname,'') + ' ' + aut_lastname AS aut_fullname, a2b_bok_id, a2b_aut_id, a2b_is_writter, a2b_is_designer FROM AUTHORS INNER JOIN BOOKS2AUTHORS ON aut_id = a2b_aut_id WHERE a2b_bok_id = @a2b_bok_id AND a2b_deleted = 0 ORDER BY aut_lastname, aut_firstname" 
        UpdateCommand="UPDATE BOOKS2AUTHORS SET a2b_is_writter=@a2b_is_writter, a2b_is_designer=@a2b_is_designer, a2b_updatedate = getDate() WHERE a2b_bok_id = @a2b_bok_id AND a2b_aut_id = @a2b_aut_id" 
        DeleteCommand="UPDATE BOOKS2AUTHORS SET a2b_deleted = 1 WHERE a2b_bok_id = @a2b_bok_id AND a2b_aut_id = @a2b_aut_id">        
        <SelectParameters><asp:ControlParameter ControlID="Label1" Name="a2b_bok_id" PropertyName="Text" /></SelectParameters>
       <UpdateParameters>
            <asp:Parameter Name="a2b_is_writter" />
            <asp:Parameter Name="a2b_is_designer" />
            <asp:Parameter Name="a2b_bok_id" />
            <asp:Parameter Name="a2b_aut_id" />
       </UpdateParameters>
       <DeleteParameters>
            <asp:Parameter Name="a2b_bok_id" />
            <asp:Parameter Name="a2b_aut_id" />
       </DeleteParameters>
        </asp:SqlDataSource>
        
        </EditItemTemplate>
    </asp:ListView>
    	   
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:mainconectionstring %>" 
        DeleteCommand="UPDATE BOOKS set bok_deleted = 1, bok_updatedate = getDate() WHERE bok_id = @bok_id" 
        InsertCommand="INSERT BOOKS (bok_title,bok_pages,bok_description,bok_originalrelease,bok_ser_index,bok_ser_id,bok_updatedate,bok_deleted,bok_file,bok_rating,bok_date,bok_nratings,bok_hasdemo,bok_sales,bok_ptr_id) VALUES (@bok_title,@bok_pages,@bok_description,@bok_originalrelease,@bok_ser_index,@bok_ser_id, getDate(),0,'',0,getDate(),0,0,0,1)" 
        SelectCommand="SELECT bok_id, bok_title, bok_pages, bok_description,  bok_originalrelease, bok_ser_index, bok_ser_id,bok_ptr_id FROM BOOKS WHERE (bok_deleted = 0) AND (bok_ser_id = @bok_ser_id) ORDER BY bok_title"         
        UpdateCommand="UPDATE BOOKS SET bok_title = @bok_title, bok_pages=@bok_pages, bok_description=@bok_description, bok_originalrelease=@bok_originalrelease,bok_ser_index=@bok_ser_index,bok_ser_id=@bok_ser_id, bok_ptr_id=@bok_ptr_id, bok_updatedate=getDate() WHERE bok_id = @bok_id">
        <SelectParameters>
            <asp:ControlParameter ControlID="DropDownList1" Name="bok_ser_id" 
                PropertyName="SelectedValue" />
        </SelectParameters>
        <DeleteParameters>
            <asp:Parameter Name="bok_id" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="bok_ptr_id" />
            <asp:Parameter Name="bok_ser_id" />
            <asp:Parameter Name="bok_ser_index" />
            <asp:Parameter Name="bok_originalrelease" />
            <asp:Parameter Name="bok_description" />
            <asp:Parameter Name="bok_pages" />
            <asp:Parameter Name="bok_title" />
            <asp:Parameter Name="bok_id" />
        </UpdateParameters>
        <InsertParameters>
            <asp:Parameter Name="bok_ser_id" />
            <asp:Parameter Name="bok_ser_index" />
            <asp:Parameter Name="bok_originalrelease" />
            <asp:Parameter Name="bok_description" />
            <asp:Parameter Name="bok_pages" />
            <asp:Parameter Name="bok_title" />
        </InsertParameters>
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
        ConnectionString="<%$ ConnectionStrings:mainconectionstring %>" 
        SelectCommand="SELECT ser_id, ser_name FROM SERIES WHERE (ser_deleted = 0) ORDER BY ser_name">
    </asp:SqlDataSource>
    
</asp:Content>
